package com.xzj.admin.boot.api.fallback;

import com.xzj.admin.boot.api.service.AdminBootService;
import com.xzj.common.core.domain.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @program: xzj-admin
 * @ClassName: AdminBootFallBackFactory
 * @description: 管理中心feign调用异常回调方法
 * @author: XiaZunJun
 * @create: 2024-06-27 11:00
 */
@Component
@Slf4j
public class AdminBootFallBackFactory implements FallbackFactory<AdminBootService> {
    @Override
    public AdminBootService create(Throwable cause) {
        log.error("调用接口Feign失败,{}",cause.getMessage());
        return new AdminBootService() {

            @Override
            public R userInfoById(String userId) {
                return R.fail(cause.getMessage());
            }

            @Override
            public R userInfoByName(String username) {
                return R.fail(cause.getMessage());
            }

            @Override
            public R menuList(String userId) {
                return R.fail(cause.getMessage());
            }

            @Override
            public R perCodeList(String userId) {
                return R.fail(cause.getMessage());
            }
        };
    }
}
